<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .red-color {
            color: #f00;
        }

        .blue-border {
            border: 1px solid #00f;
        }
    </style>
</head>
<body>
    <div class="div1">我是div1</div>
    <div class="div2">我是div2</div>
    <button class="btn1">添加颜色</button>
    <button class="btn3">移除颜色</button>
    <button class="btn2">添加边框</button>
    <button class="btn4">移除边框</button>
    <button class="btn5">切换颜色和边框</button>
    <div>
        <span>姓名：</span>
        <p class="p1">奉先</p>
    </div>

</body>
<script>
    let div1 = document.querySelector(".div1");
    console.log("div1 =",div1);

    let div2 = document.querySelector(".div2");
    console.log("div2 =",div2);
    
    console.log(div1.innerText);

    div1.innerText = '<h1>我是h1</h1><p>我是p标签</p>';
    div2.innerHTML = '<h1>我是h1</h1><p>我是p标签</p>';

    console.log("div1.innerText = ",div1.innerText);
    console.log("div2.innerHTML = ",div2.innerHTML);

    // 查找按钮，然后绑定事件
    let btn1 = document.querySelector(".btn1");
    let btn2 = document.querySelector(".btn2");
    let btn3 = document.querySelector(".btn3");
    let btn4 = document.querySelector(".btn4");
    let btn5 = document.querySelector(".btn5");

    // 给按钮1添加点击事件的处理函数
    btn1.addEventListener("click",function() {
        // classList.add()：添加指定class
        div1.classList.add("red-color");
        div2.classList.add("red-color");
    });

    // 添加边框按钮
    btn2.addEventListener("click",function() {
        div1.classList.add("blue-border");
        div2.classList.add("blue-border");
    });

    // 移除颜色按钮
    btn3.addEventListener("click",function() {
        div1.classList.remove("red-color");
        div2.classList.remove("red-color");
    });

    // 移除边框按钮
    btn4.addEventListener("click",function() {
        div1.classList.remove("blue-border");
        div2.classList.remove("blue-border");
    });

    // 切换颜色和边框
    btn5.addEventListener("click",function() {
        div1.classList.toggle("red-color");
        div2.classList.toggle("red-color");

        div1.classList.toggle("blue-border");
        div2.classList.toggle("blue-border");
    });
</script>
</html>